<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<jsp:include page="/WEB-INF/backstage/util.jsp"/>
<script type="text/javascript">

//下一页
function tonext(){

	/* var page=${pb.currentPage+1}>${pb.totalpage}?${pb.totalpage}:${pb.currentPage+1};
	alert("下一页"+page); */
	document.forms[0].action="finduser_shop?page="+${info.nextPage};
	document.forms[0].submit();
}
//上一页
function toup(){
	/* var page=${pb.currentPage-1}<1?1:${pb.currentPage-1};
	alert("上一页"+page); */
	document.forms[0].action="finduser_shop?page="+${info.prePage};
	document.forms[0].submit();
}

</script>
</head>
<body>

<form class="form-inline" role="form"  method="post" action="finduser_shop">
<table >
<tr>
<td><label>用户编号</label></td>
<td><input type="text" class="form-control" name ="shop_user_id" id="shop_user_id"></td>
<td><label>店铺名称</label></td>
<td><input class="form-control" type="text" name ="shop_name" id="shop_name"></td>
<td> <label>状态</label></td>
<td><select class="form-control" name="show_status" id="show_status">
  <option value=""></option>
  <option value="0">停用</option>
  <option value="1">启用</option>
  </select></td>
  <td>&nbsp;&nbsp;</td>
  <td rowspan="2"><button type="submit" class="btn btn-primary">查询</button>&nbsp&nbsp</td>
  <td rowspan="2"><button type="button" class="btn btn-primary" id="clear">重置</button>&nbsp
  <button type="button" class="btn btn-primary"  data-toggle="modal" data-target="#myModal">添加</button>
   </td>
</tr>
<tr>
<td><label>店主账号</label></td>
<td><input type="text" class="form-control" name ="account" id="account"></td>

<td><label>营业执照号</label></td>
<td><input class="form-control" type="text" name ="shop_license" id="shop_license"></td>
</tr>
</table>
</form>
<table border="1" width="1000"  class="table table-striped" class="table table-hover" id="table1" name="table1">

<tr style="background-color: #E6EEF8">
<td>&nbsp&nbsp&nbsp&nbsp</td>
<td>用户编号</td>
<td>店铺名称</td>
<td>店铺简称</td>
<td>店主账号</td>
<td>店铺法人</td>
<td>营业执照号</td>
<td>手机号</td>
<td>邮箱</td>
<td>状态</td>
<td>更新时间</td>
<td></td>
</tr>
<c:forEach items="${info.list }" var="list">
<tr >
<td id="t1">&nbsp&nbsp&nbsp&nbsp</td>
<td id="shop_user_id">${list.shop_user_id }</td>
<td>${list.shop_name }</td>
<td>${list.short_name }</td>
<td>${list.account }</td>
<td>${list.username} </td>
<td>${list.shop_license }</td>
<td>${list.mobile }</td>
<td>${list.email }</td>
<td>${list.show_status=="1"?"启用":"禁用" }</td>
<td>${list.modify_time }</td>
<td>
<a href="deleteshopuser1/${list.shop_user_id }"  class="btn btn-primary btn-xs" role="button">删除</a>
<a href="toupdateshopuser/${list.shop_user_id}" class="btn btn-primary btn-xs" role="button">修改</a>
<!-- <button  class="btn btn-primary btn-xs" type="button" onclick="test1(this)" data-toggle="modal" data-target="#myModal2" >密码重置</button> -->
</td>
</tr>
</c:forEach>
</table>
<a href="#"  onclick="toup()">上一页</a>&nbsp;&nbsp;&nbsp;
<a href="#"   onclick="tonext()">下一页</a>


<!-- Modal -->
<!--添加模态框  -->
<div  class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" style="width: 750px;">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" onclick="clear2()" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span></button>
        <h4 class="modal-title" id="myModalLabel" align="center">添加用户</h4>
      </div>
      <div class="modal-body">
 <form  method="post" id="form1" class="form-horizontal">
 <table border="0" width="800" height="300"  class="form-inline" >
        
        <tr>
        <td align="right"><label for="account" >店铺简称:</label></td>
        <td>
        <select name="shop_id" class="form-control">
        <c:forEach items="${list3 }" var="shopuser">
        <option value="${shopuser.shop_id }">${shopuser.short_name }</option>
        </c:forEach>
       </select>
        </td>
         <td align="right"><label for="account" >状态:</label></td>
        <td>
		<select  name="status" id="status" class="form-control">
		<option value="1">启用</option>
		<option value="0">禁用</option>
		</select>
		</td>
        </tr>
          <tr>
         <td align="right"><label for="account" >账号:</label></td>
        <td>
    	<div class="form-group">
			
			<div class="col-sm-10">
				<input type="text" class="form-control" id="account2"
					name="account" placeholder="请输入账号">
			</div>
		</div>
        </td>
        <td align="right"><label for="account" >姓名:</label></td>
        <td><input type="text" class="form-control" name ="username" id="username"></td>
        </tr>
       
        <tr>
         <td align="right"><label for="account" >身份证:</label></td>
        <td><input type="text" class="form-control" name ="idno" id="idno"></td>
        <td align="right"><label for="account" >邮箱:</label></td>
        <td><input type="text" class="form-control" name ="email" id="email"></td>
        </tr>
        
        <tr>
         <td align="right"><label for="account" >手机号:</label></td>
        <td>
        	<div class="form-group">
			
			<div class="col-sm-10">
				<input type="text" class="form-control" id="mobile"
					name="mobile" placeholder="请输入手机号">
			</div>
			</div>
        </td>
       <td align="right"><label for="account" >职务:</label></td>
        <td>
        	<div class="form-group">
			<div class="col-sm-10">
				<select name="post_code" class="form-control" id="post_code">
      		
        </select>
			</div>
			</div>
        
        </td>
         
        </tr>
          <tr align="center">
        <td colspan="4" align="center">
        <button type="button" class="btn btn-primary" onclick="clear2()">重置</button>
        <input type="button"  class="btn btn-primary"  value="提交" onclick="addbtn()">
        </td>
        </tr>

        </table>
        </form>
      </div>
    </div>
  </div>
</div>

</body>
</html>

<script type="text/javascript">
//填充下拉框
$(function(){
	$.ajax({
		type:"post",
		url:"${pageContext.request.contextPath }/selectBis_shop_post",
		success:function(msg){
			$.each(msg,function(index,post){
				var option="<option value="+post.post_code+">"+post.post_name+"</option>";
				$("#post_code").append(option);
			})
		}
	})
})


//保存
function addbtn(){
	var bootstrapValidator = $("#form1").data('bootstrapValidator'); //获取表单对象
	bootstrapValidator.validate();//触发全部验证 
	if(bootstrapValidator.isValid()){
		form1.action="${pageContext.request.contextPath }/insertshopuser";
		form1.submit();
	}
}

//点击密码重置 将当前行数据ID传递到模态框
function test1 (obj) {
	var $td = $(obj).parents('tr').children('td');
    var shop_user_id = $td.eq(1).text();
	$("#pad").val(shop_user_id);//将获取的该行的id值填充到模态框的文框中，文本框的id为pad，其他的数据也是如此处理
}

$("#clear").click(
		function() {
			$("#form1").data('bootstrapValidator').resetForm(); //刷新表单
			$("#shop_user_id").val("");
			$("#shop_name").val("");
			$("#show_status").val("");
			$("#account").val("");
			$("#shop_license").val("");
		}
	);
	
		function clear2() {
			$("#form1").data('bootstrapValidator').resetForm(); //刷新表单
			$("#account2").val("");
			$("#username").val("");
			$("#status").val("");
			$("#idno").val("");
			$("#email").val("");
			$("#mobile").val("");
			$("#post_code").val("");
		}
	
	
	$(function(){
		$("#form1").bootstrapValidator({
			live : 'enabled',
			feedbackIcons : { //验证时显示的图标
				valid : 'glyphicon glyphicon-ok', //正确图标
				invalid : 'glyphicon glyphicon-remove', //错误图标
				validating : 'glyphicon glyphicon-refresh' //正在更新图标
			},
			fields : { //要验证哪些字段
				account : {
					validators : {//验证
						notEmpty : { //非空判断
							message : '用户名不能为空' //验证错误时的信息，
						},
						regexp : { //正则表达式判断 
							regexp : /^[a-zA-Z0-9_]+$/, //表达式内容
							message : '用户名只能为字母和数组组成' //验证错误时的信息，
						},
						 remote : {
								message : '用户名已存在',
								url : '${pageContext.request.contextPath }/checkAccount',
								type : 'post',
								delay : 2000,//每输入一个字符，就发ajax请求，服务器压力还是太大，设置2秒发送一次ajax（默认输入一个字符，提交一次，服务器压力太大）
								data:function(validator){
									return{
										account:$("#account2").val()
									}
								}
							} 
					},
				},	
				mobile:{
					validators : {//验证
						notEmpty : { //非空判断
							message : '电话不能为空' //验证错误时的信息，
						},
						stringLength : {//长度判断
							message : '请输入11位手机号码',//验证错误信息
							min : 11,//不得小于
							max : 11//不得大于
						},
						 remote : {
								message : '手机号码已存在',
								url : '${pageContext.request.contextPath }/checkMobile',
								type : 'post',
								delay : 2000,//每输入一个字符，就发ajax请求，服务器压力还是太大，设置2秒发送一次ajax（默认输入一个字符，提交一次，服务器压力太大）
								data:function(validator){
									return{
										mobile:$("#mobile").val()
									}
								}
							} 
					},
				}
			}
		});
	});
	
	
</script>
